import React, { Component } from 'react'
import "./myactivity.scss"
import { message } from 'antd';
import { getApiMySign , getApiQXsign } from '../../axios/api';
import { get } from '../../axios/localstorage';

export default class myactivity extends Component {

    state = {
        page:1,
        total:1,
        list:[],
    }

    componentWillMount(){
        this.getList();
    }

    getList=()=>{
        let param = {
            token:get('token'),
            type:get('type')?get('type'):0,
            content:get('city')?get('city'):get('mechanism'),
            // page:this.state.page,
        }

        getApiMySign(param)
        .then( req =>{
            if(req.data.code === 1){
                let data = req.data.data;
                this.setState({
                    list:data.list
                })
            }
        }).catch( err =>{
            console.error(err);
        })
    }

    changePage=(page)=>{
        this.setState({
            page
        })
    }

    gotoPage=(page)=>{
        this.props.history.push(page);
    }

    gotoCancel=(id)=>{
        let param = {
            token:get('token'),
            id
        }
        getApiQXsign(param)
        .then( req =>{
            if(req.data.code === 1){
                message.success(req.data.msg);
                this.getList();
            }else{
                message.info(req.data.msg);
            }
        }).catch( err =>{
            console.error(err);
        })
    }

    render() {
        return (
            <div className='myactivity'>
                <div className='mpage'>
                    <div className='title'>我的活动</div>
                    <div className='ptable'>
                        <table>
                            <tr>
                                <th>申请人</th>
                                <th>申请信息</th>
                                <th>申请时间</th>
                                <th>申请活动</th>
                                <th>申请状态</th>
                                <th className='two'>申请操作</th>
                            </tr>
                            {
                                this.state.list.map((item,index)=>{
                                    return <tr>
                                                <td>{item.nickname}</td>
                                                <td className='green i_point' onClick={()=>{this.gotoPage('/signupinfo?id='+item.sign_id)}}>查看信息</td>
                                                <td>{item.createtime_text}</td>
                                                <td className='green'>{item.title}</td>
                                                <td className='yellow' hidden={item.status !== 0}>申请中</td>
                                                <td className='green' hidden={item.status !== 1}>申请成功：{item.fraction}分</td>
                                                <td className='gracy' hidden={item.status !== 3}>申请取消</td>
                                                <td className='yellow' hidden={item.status !== 2}>申请失败</td>
                                                <td>
                                                    <div className='options'>
                                                        <div className='opi' hidden={item.status === 1} onClick={()=>{this.gotoPage('/productSignup?id='+item.sign_id+'&sign_id='+item.sign_id)}}>
                                                            <img alt="" src='assets/img/bianji.png' />
                                                            <p className='blue'>编辑</p>
                                                        </div>
                                                        <div className='opi' onClick={()=>{this.gotoCancel(item.sign_id)}} hidden={item.status === 3}>
                                                            <img alt="" src='assets/img/quxiao.png' />
                                                            <p>取消</p>
                                                        </div>
                                                    </div>
                                                </td>
                                            </tr>
                                })
                            }
                        </table>
                    </div>

                    <div className="none" hidden={this.state.list.length !== 0}>
                            <div className="cen">
                                <img alt="" src="assets/imgs/zanwuxuexineirong.png" />
                            </div>
                            <p>暂无我的活动</p>
                        </div>
                </div>

                {/* <div className='r_page'>
                    <Pagination type="primary" showSizeChanger={false} pageSize={10}  defaultCurrent={this.state.page} total={this.state.total} onChange={(page)=>{this.changePage(page)}} />
                </div> */}
            </div>
        )
    }
}
